package com.ndky.annotation.reflect.two;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * 通过反射获取方法,属性
 * author: 核桃
 * date: 2023/11/16
 **/
public class TestTwo {
    public static void main(String[] args) throws ClassNotFoundException {

        // 通过反射获取对象
        Class userClass = Class.forName("com.ndky.annotation.reflect.two.UserTwo");

        // 获取反射对象的方法
        Method[] declaredMethods = userClass.getDeclaredMethods();
        // 遍历输出
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod);
        }

        System.out.println("==========================");
        // 获取反射对象的属性
        Field[] declaredFields = userClass.getDeclaredFields();
        // 遍历输出
        for (Field declaredField : declaredFields) {
            System.out.println(declaredField);
        }
    }
}
